def calc(x):
    if x == 1: return False
    chislo = True
    k = x - 1
    while k > 1:
        if not x % k:
            chislo = False
            break
        k -= 1
    return chislo

n = input()
r = []
if 10000 > int(n) >999:
        for i in range(len(n)):
                for k in range(i + 1, len(n) + 1):
                        x = int(n[i:k])
                        if calc(x):
                                r += [x]
        print(max(r) if r else 0)
else:
        print(0)